- 
                Notifications
    
You must be signed in to change notification settings  - Fork 6
 
MB-62985 - Add functionality to support binary quantised vectors. #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
0299389    to
    4132f92      
    Compare
  
    | 
               | 
          ||
| go 1.21 | ||
| go 1.22 | ||
| 
               | 
          
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was changed in a recent patch so update.
This reverts commit 73e9e4b.
        
          
                index.go
              
                Outdated
          
        
      | return int(C.faiss_IndexBinary_d(idx.idxBinary)) | ||
| } | ||
| 
               | 
          ||
| func (idx *faissIndex) IsTrained() bool { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If index is binary then calling this method would panic right as you should be calling
return C.faiss_IndexBinary_is_trained(idx.idx) != 0
        
          
                index.go
              
                Outdated
          
        
      | return | ||
| } | ||
| 
               | 
          ||
| func (idx *faissIndex) SearchBinaryWithIDs(x []uint8, k int64, | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- please add all binary index related methods(and the struct) to a new file, after splitting the interface thanks
 - The method naming is off, youre just searching the binary vector with a given K - No IDs for an include selector is given, Rename to Just SearchBinary
 
        
          
                index.go
              
                Outdated
          
        
      | } | ||
| defer searchParams.Delete() | ||
| 
               | 
          ||
| if c := C.faiss_IndexBinary_search_with_params( | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code block can be reused. Add searchBinaryWithParams method similar to searchWithParams
| tempBuf := (*C.uchar)(nil) | ||
| bufSize := C.size_t(0) | ||
| 
               | 
          ||
| if c := C.faiss_write_index_binary_buf( | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lot of code duplication here; following my earlier comment of split interfaces, you can just reuse the existing method
func WriteIndexIntoBuffer(idx BaseIndex) ([]byte, error) {
// the values to be returned by the faiss APIs
	tempBuf := (*C.uchar)(nil)
	bufSize := C.size_t(0)
	switch i := idx.(type) {
	case BinaryIndex: // Child Interface check - Will be binary index struct if has the TrainBinary method
		status = C.faiss_write_index_binary_buf(
			(*C.FaissIndexBinary)(i.(*binaryIndex).idx),
			&bufSize,
			&tempBuf,
		)
	case FloatIndex:  // Child Interface check - Will be float index struct if has the IVF methods (example
		status = C.faiss_write_index_buf(
			(*C.FaissIndex)(i.(*floatIndex).idx),
			&bufSize,
			&tempBuf,
		)
	default:
		return nil, fmt.Errorf("unsupported index type: %T", idx)
	}
// Rest of the method unchanged
        
          
                index_io.go
              
                Outdated
          
        
      | return &IndexImpl{&idx}, nil | ||
| } | ||
| 
               | 
          ||
| func ReadBinaryIndexFromBuffer(buf []byte, ioflags int) (*IndexImpl, error) { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not need a new method, just pass a flag, maybe expose a enum to zapx that can
type IndexType int
const (
    FloatIndexType IndexType = iota // 0
    BinaryIndexType                  // 1
)
func ReadIndexFromBuffer(buf []byte, ioflags int, idxType IndexType) () {
``
a961c59    to
    5dd343f      
    Compare
  
    b779132    to
    2c060eb      
    Compare
  
    1226060    to
    20b3ae4      
    Compare
  
    
Uh oh!
There was an error while loading. Please reload this page.